﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SundayWishModel.Entities;
using NHibernate;

namespace SundayWishBLL
{
    public class DishHelper
    {
        protected int DishPublic;

        public virtual Dish GetDish(int DishId)
        {
            ISession Session = NHibernateHelper.GetSession();
            return Session.Get<Dish>(DishId);
        }


        public virtual Boolean AddDish(Dish dish)
        {
            ISession Session = NHibernateHelper.GetSession();
            dish.DishPublic = DishPublic;
            Session.Save(dish);
            Session.Flush();
            return true;
        }

        public virtual Boolean DeleteDish(Dish dish)
        {
            ISession Session = NHibernateHelper.GetSession();
            Session.Delete(dish);
            Session.Flush();
            Session.CreateSQLQuery("Delete From Plan_Dish where DishId = :di")
            .SetParameter("di", dish.DishId.ToString()).ExecuteUpdate();
            return true;
        }

        public virtual Boolean UpdateDish(Dish dish)
        {
            ISession Session = NHibernateHelper.GetSession();
            dish.DishPublic = DishPublic;
            Session.SaveOrUpdate(dish);
            Session.Flush();
            return true;
        }
    }
}
